Ext.ns('ViewField');
ViewField.ds = new Ext.data.Store({
	sortInfo:{field: 'id', direction: 'ASC'},
	reader: new Ext.data.JsonReader({
		root:'result',
		totalProperty:'totalCount',
		fields :[
		         {name:'id',type:'int'},
		         {name:'name'},
		         {name:'enable'},
		         {name:'reqType'},
		         {name:'eng'},
		         {name:'chi'},
		         {name:'cht'},
		         {name:'tip'}
		         
		         ]
		  
		}),
	proxy : new Ext.data.HttpProxy( {  
 	        url :contextURL+'ViewFieldServlet', 
 	        method :'GET'  
 	    })
	});
ViewField.columns = [ {
 			header : "id",
 			id:'id',
 			width : 90,
 			sortable : true,
 			dataIndex : 'id'
 		}, {
			id : 'name',
			header : "name",
			width : 200,
			sortable : true,
			dataIndex : 'name'
		},{
			header : "enable",
			width : 90,
			sortable : true,
			dataIndex : 'enable'
		}, {
			header : "reqType",
			width : 90,
			sortable : true,
			dataIndex : 'reqType'
		}, {
			header : "Eng",
			width : 90,
			sortable : true,
			dataIndex : 'eng'
		}, {
			header : "SChi",
			width : 90,
			sortable : true,
			dataIndex : 'chi'
		}, {
			header : "TChi",
			width : 90,
			sortable : true,
			dataIndex : 'cht'
		}, {
			header : "tip",
			width : 400,
			sortable : false,
			dataIndex : 'tip'
		} ];

ViewField.tbar = [ 'Field ID/Eng/TChi/SChi','',
		   {
			   id:'code',
			xtype:'field',
				width:200,
				 listeners : {  
                    specialKey : function(field, e) {  
                        if (e.getKey() == Ext.EventObject.ENTER) {
                        	ViewField.requestHandler();   
                        }  
                    } 
			}
                
       }," "," "
		    ,'-',
          {
          	xtype:'button',
          	text:'Search',
          	handler: function(){
			   ViewField.requestHandler();
		    }
          }
];
ViewField.bbar = new Ext.PagingToolbar({    
    pageSize: 15,    
    store: ViewField.ds,    
    displayInfo: true,    
    displayMsg: '第{0} 到 {1} 条数据 共{2}条',    
    emptyMsg: "没有数据"    
});

ViewField.ChartPanel = Ext.extend(Ext.Panel, {
	//renderTo: 'binding-example',
	frame: true,
	title: 'ViewField List',
	//width: 540,
	//height: 400,
	layout: 'border',
	initComponent :function(){
	   this.items = [
	     	   		{
	    				id: 'urlPanel',
	    				region: 'north',
	    				bodyStyle: {
	    					background: '#ffffff',
	    					padding: '7px'
	    				},
	    				html: '<a>url....</a>'
	    			},
	    			ViewField.ChartGrid
	    		];
	   	
	   Ext.Panel.superclass.initComponent.apply(this, arguments);
	   Ext.getCmp("code").focus();
	   ViewField.ds.load();
	}
});
ViewField.initload = function (){
	Ext.getCmp("code").focus();
};
ViewField.requestHandler = function requestHandler() {	
	var urls =contextURL+'ViewFieldServlet';
	var code = Ext.get("code").dom.value;
	if(code!=""){
		urls = urls+"?fieldid="+code;
		//escape(encodeURIComponent(code));
	}
	 	
	Ext.getDom("urlPanel").innerHTML = "<a href='" + urls + "' target='_blank'>" + urls + "</a>";
	var mk = new Ext.LoadMask(Ext.getBody(), {
		msg: '正在更新数据，请稍候！'
	});
	mk.show(); 
	
	ViewField.ds.proxy = new Ext.data.HttpProxy( {  
        url :urls,  
        method :'GET'  
    });
	//store.loadData(data,false);
	ViewField.ds.load();
	//ViewField.ds.load({params:{start:0,limit:15}});
	mk.hide();
	Ext.getCmp("code").focus();
	//var obj= Ext.decode(response.responseText); 
	
	/*
	Ext.Ajax.request( {
		url : urls,
		method : "GET",
		success : function(result, request) {
			var objDate= Ext.decode(result.responseText);
			alert(objDate.totalCount);
//			ViewField.ds.proxy = new Ext.data.PagingMemoryProxy(objDate);
		//store.loadData(data,false);
//			ViewField.ds.load({params:{start:0,limit:15}});
		
		//store.load({params:{start:0, limit:10}});
		// contextURL + url + "?" + Ext.urlEncode(param);
       // Ext.getDom("urlPanel").innerHTML = "<a href='" + urls + "' target='_blank'>" + urls + "</a>";
		//Ext.getDom('jsonpanel').innerHTML =result.responseText.replace('\n','\t');
		//.split("\n");; 
			//strs[0].split(',')+"||"+strs[1].split(',');

		// Ext.getCmp('jsonpanel').repla();
		// var result = eval("(" + data.responseText + ")").result;
		// this.store.reader = reader;
		// this.store.proxy.data = result;
		// this.store.load({params:{start:0,limit:20}});

			mk.hide();
			Ext.getCmp("code").focus();
		},
		failure : function(result, request) {
			Ext.MessageBox.alert('访问失败', '失败了就没好说的了  (*^__^*) 嘻嘻……: ');
			mk.hide();
		}
			// ,scope : this
			// params: param
		});*/
};
ViewField.DetailMsg = new Ext.Window({
	layout:'fit',
	width:500,
	height:300,
	closeAction:'hide',
	title:'detail',
	html:'',
	modal :true,
	items:[{id:'detailMsg',
			xtype:'textarea',
			readOnly : true,
				width:60}],
	buttons:[{text:'OK',
	         handler:function(){
			ViewField.DetailMsg.hide();
	}}]
});
ViewField.ChartGrid =  new Ext.grid.GridPanel({
	loadMask: {msg:'正在加载数据...'},
	//renderTo: document.body,
	region: 'center',
	//autoHeight: true,
    //autoWidth:true,
    autoScroll: true,
	layout:'fit',
	title : 'View Field',
	store: ViewField.ds,
	columns:ViewField.columns,
	tbar:ViewField.tbar,
	//bbar:ViewField.bbar,
	listeners:{
		'rowdblclick' : function(grid, rowIndex, e){  
        //grid.getSelectionModel().clearSelections();  
        //alert(grid.getSelectionModel().selectRow(rowIndex).get("tip"));
		 var msg = grid.getSelectionModel().getSelected().get('tip');
		 //Ext.MessageBox.alert("detail",msg);
		 //ViewField.DetailMsg.html = "<h1 >"+msg+"</h1>";
		 Ext.getCmp("detailMsg").setValue(msg);
		 ViewField.DetailMsg.show();
		 
        // alert(rowIndex+'---'+grid.id);  
		},
		'load' : function() {
            //grid.getSelectionModel().selectRow(1);   
        }   
	}
});

Ext.onReady(function(){
	//BrokerAnalysis.ChartGrid.render(document.body);
	new ViewField.ChartPanel({
		frame: true,
		layout:'border',
		renderTo: 'grid-example',
		height : 600,
		width : 1000		
	});
	//window.body.on('load',function(){alert("haja");});
});
	
